<template>
  <div class="message-custom">
    <MessageRating
      v-if="isMessageRating(props.message)"
      :message="props.message"
      @sendMessage="sendCustomMessage"
    />
    <MessageCustomerService
      v-else-if="isCustomerServiceMessage(props.message)"
      :message="props.message"
      @sendMessage="sendTextMessage"
      @sendCustomMessage="sendCustomMessage"
      @showFormPopup="handleShowFormPopup"
    />
  </div>
</template>
<script lang="ts">
import TUICore, { TUIConstants } from '@tencentcloud/tui-core';
import { isCustomerServiceMessage, isMessageRating } from './utils/index';
import { CustomMessagePayload, TextMessagePayload, IMessageModel } from './interface';
import MessageCustomerService from './components/message-customer-service.vue';
import MessageRating from './components/message-rating/index.vue';
import TUIChatEngine, {
  TUIChatService,
} from '@tencentcloud/chat-uikit-engine';
interface Props {
  message: IMessageModel;
}
export default {
  components: {
    MessageCustomerService,
    MessageRating,
  },
  props: {
    message: {
      type: Object as () => IMessageModel,
      default: () => ({}),
    },
  },
  emits: ['showFormPopup'],
  setup(props: Props, { emit }) {
    const sendTextMessage = (payload: TextMessagePayload) => {
      TUIChatService.sendTextMessage({payload});
      // TUICore.callService({
      //   serviceName: TUIConstants.TUIChat.SERVICE.NAME,
      //   method: TUIConstants.TUIChat.SERVICE.METHOD.SEND_TEXT_MESSAGE,
      //   params: { payload },
      // });
    };
    const sendCustomMessage = (payload: CustomMessagePayload) => {
      TUIChatService.sendCustomMessage({payload});
      // TUICore.callService({
      //   serviceName: TUIConstants.TUIChat.SERVICE.NAME,
      //   method: TUIConstants.TUIChat.SERVICE.METHOD.SEND_CUSTOM_MESSAGE,
      //   params: { payload },
      // });
    };
    const handleShowFormPopup = (data: boolean) => {
      emit('showFormPopup', data);
    }
    return {
      props,
      sendTextMessage,
      sendCustomMessage,
      isCustomerServiceMessage,
      isMessageRating,
      handleShowFormPopup
    };
  },
};
</script>
